Stop Watch

I have a gui that I have a button to stop and start, It currently stop and starts the current time and not at 0. How do I change this? I also want to take the final value and save it to an object text box at the top of my test. Suggestions please?!

DB db = null
DBE dbeClock = null
DBE dbeTime = null
DBE dbeStart = null
DBE dbeStop = null
int interval = 1
// CB on timer updates display passing in value of today gives current date and time I want todays date //and 0:00 time
void doClock(DBE dbe)
{
string s1 = stringOf(dateAndTime(today))
set(dbeTime, s1)
}

// start the clock
void doStart(DB db)
{
if (startTimer(dbeClock))
{
inactive(dbeStart)
active(dbeStop)
}
}

// stop the clock
void doStop(DB db)
{
if (stopTimer(dbeClock))
{
active(dbeStart)
inactive(dbeStop)
}
}

db = create(dbExplorer, "Test Portal", styleCentered)

dbeTime = field(db, "Current time", "", 20, true)

// create the timer.
dbeClock = timer(db, interval, doClock, "")

dbeStart = apply(db, "Start", doStart)
dbeStop = apply(db, "Stop", doStop)

realize db

setCenteredSize(db, 250, 100)
inactive(dbeStart)
show db
JesLewis - Fri Mar 02 14:10:04 EST 2012

Re: Stop Watch
llandale - Fri Mar 02 14:50:34 EST 2012

I don't have DOORS in front of me to prove the following, but I think this works:
I think you want a global int variable representing how long since you started timing. Function doClock() simply increments the timer and then <set(dbeTime, TimeSeconds "")>. function doStop() turns off the timer. Function doStart() sets the global int to zero and starts the timer.

If you didn't use a DBE timer, then doStart would capture the current time in seconds in the global variable and doStop would get the current time and subtract the original start time.

I have a nagging memory that the "timer" needs a title, the last parameter. If so, perhaps the name of the script will do.

-Louie

Re: Stop Watch
JesLewis - Mon Mar 05 14:00:10 EST 2012

llandale - Fri Mar 02 14:50:34 EST 2012
I don't have DOORS in front of me to prove the following, but I think this works:
I think you want a global int variable representing how long since you started timing. Function doClock() simply increments the timer and then <set(dbeTime, TimeSeconds "")>. function doStop() turns off the timer. Function doStart() sets the global int to zero and starts the timer.

If you didn't use a DBE timer, then doStart would capture the current time in seconds in the global variable and doStop would get the current time and subtract the original start time.

I have a nagging memory that the "timer" needs a title, the last parameter. If so, perhaps the name of the script will do.

-Louie

I figured it out, but if anyone else needs it:

DB db = null
DBE dbeClock = null
DBE dbeTime = null
DBE dbeStart = null
DBE dbeStop = null
int interval = 1
int startTime = 0
int elapsedTime = 0

// start the clock
void doStart(DB db)
{
Date d = today
startTime = intOf(d)
//Adjust for any previously elapsed time not reset
startTime = startTime - elapsedTime
if (startTimer(dbeClock))
{
inactive(dbeStart)
active(dbeStop)
}
}

// stop the clock
void doStop(DB db)
{
if (stopTimer(dbeClock))
{
active(dbeStart)
inactive(dbeStop)
}
}
// CB on timer updates display
void doClock(DBE dbe)
{
Date d = null
int currentTime = null
int seconds = 0
int minutes = 0
int hours = 0
int days = 0

d = today
currentTime = intOf(d)
elapsedTime = currentTime - startTime
seconds = elapsedTime % 60
minutes = (elapsedTime % 3600) / 60
hours = (elapsedTime % 86400) / 3600
days = elapsedTime / 86400
string s1 = days " d:" hours " h:" minutes " m:" seconds " s"
set (dbeTime, s1)
}

// reset the clock
void doReset(DB db)
{
elapsedTime = 0
string s1 = "0 d:0 h:0 m:0 s"
set (dbeTime, s1)
if (stopTimer(dbeClock))
{
active(dbeStart)
inactive(dbeStop)
}
}

db = create(dbExplorer, "Test Portal", styleCentered)

dbeTime = field(db, "Elapsed Time", "", 20, true)

// create the timer.
dbeClock = timer(db, interval, doClock, "")
doStart(db)

dbeStart = apply(db, "Start", doStart)
dbeStop = apply(db, "Stop", doStop)
dbeReset = apply(db, "Reset", doReset)

realize db

setCenteredSize(db, 250, 100)
inactive(dbeStart)
show db

Re: Stop Watch
BeastBoysDad - Fri Oct 04 18:41:28 EDT 2013

The timer function referenced above is not documented in the DOORS DXL Reference Manual.  I've asked IBM to provide documentation and they declined.  I've submitted an RFE to ask IBM to add the timer function to the DXL Reference Reference Manual.  Please vote on the proposed RFE at http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=39914.